﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Users_CustomerCollect : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSThemes();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = BasePage.WebTitle;
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            Init_Collection();
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
    }
    private void Init_Collection()
    {
        StringBuilder TableName = new StringBuilder();
        StringBuilder FiledList = new StringBuilder();
        StringBuilder WhereStr = new StringBuilder();
        TableName.Append("V_COLLECT inner join ShangPin on V_COLLECT.ProductID=ShangPin.SPDM ");
        TableName.Append("left join COMMODITY_AUTO on V_COLLECT.ProductID=COMMODITY_AUTO.CA_CODE  ");
        TableName.Append("left join COMMODITY_PIC on V_COLLECT.ProductID=COMMODITY_PIC.CP_CODE and CP_STOP=0 and CP_DEFAULT=1 and CP_PART=0");
        FiledList.Append("ID,");
        FiledList.Append("UserId,");
        FiledList.Append("ProductID,");
        FiledList.Append("ProductName=case when len(CA_Name)>0 then CA_Name else SPMC end,");
        FiledList.Append("CP_COLOR,");
        FiledList.Append("CP_PICPATH,");
        FiledList.Append("AddTime,IsDel ");
        WhereStr.Append("and [UserId] = '" + BasePage.GetValue(0) + "' and IsDel=0");
        int pageCount, rowCount;
        Repeater1.DataSource = new BLL.V_COLLECT().GetUserCollect(TableName.ToString(), FiledList.ToString(), AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "AddTime", false, WhereStr.ToString(), out pageCount, out rowCount);
        Repeater1.DataBind();
        AspNetPager1.RecordCount = rowCount;
    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            string id = e.CommandArgument.ToString();
            if (new BLL.V_COLLECT().Delete(int.Parse(id)))
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('删除成功!')", true);
                Init_Collection();
            }
        }
    }
}
